package com.campusbook.dao;

import com.campusbook.model.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface UserDao {
    
    @Select("SELECT * FROM users WHERE id = #{id}")
    User findById(Long id);
    
    @Select("SELECT * FROM users WHERE username = #{username}")
    User findByUsername(String username);
    
    @Select("SELECT * FROM users")
    List<User> findAll();
    
    @Insert("INSERT INTO users(username, password, email, full_name, phone, avatar_url, status, role) " +
            "VALUES(#{username}, #{password}, #{email}, #{fullName}, #{phone}, #{avatarUrl}, #{status}, #{role})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(User user);
    
    @Update("UPDATE users SET username=#{username}, email=#{email}, full_name=#{fullName}, " +
            "phone=#{phone}, avatar_url=#{avatarUrl}, status=#{status}, role=#{role}, updated_at=NOW() " +
            "WHERE id=#{id}")
    void update(User user);
    
    @Delete("DELETE FROM users WHERE id = #{id}")
    void delete(Long id);
    
    @Select("SELECT COUNT(*) FROM users WHERE username = #{username}")
    int countByUsername(String username);
    
    @Select("SELECT COUNT(*) FROM users WHERE email = #{email}")
    int countByEmail(String email);
}
